package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.service.NursingProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Cat
 * @date 2024/5/28 11:22
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags ="护理项目控制接口")
@Slf4j
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;

    @ApiOperation("根据分页条件查询")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(@ApiParam(value = "护理项目名称")  String name,
                                                                    @ApiParam(value = "状态") Integer status,
                                                                    @ApiParam(value = "当前页码")@RequestParam( required = true,defaultValue = "1") Integer pageNum,
                                                                    @ApiParam(value = "每页显示数量")@RequestParam(required = true,defaultValue = "10")Integer pageSize){
        PageResponse<NursingProjectVo> pageVo = nursingProjectService.getByPage(name,status,pageNum,pageSize);
        return success(pageVo);
    }

    @ApiOperation("新增护理项目")
    @PostMapping()
    public ResponseResult insertNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.insertNursingProject(nursingProjectDto);
        return success();
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public  ResponseResult<NursingProjectVo> getById(@ApiParam(value = "id") @PathVariable Long id){
        NursingProjectVo vo = nursingProjectService.getById(id);
        return success(vo);
    }

    @ApiOperation("修改")
    @PutMapping()
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ResponseResult del(@ApiParam(value = "id")@PathVariable Long id){
        nursingProjectService.del(id);
        return success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Long id,
                                       @PathVariable Integer status){
        nursingProjectService.updateStatus(id,status);
        return success();
    }

}
